package com.hxc.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hxc.entity.PageBean;
import com.hxc.entity.Student;
import com.hxc.entity.StudentQueryParam;
import com.hxc.mapper.StudentMapper;
import com.hxc.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    /**
     * 分页查询
     * */
    @Override
    public PageBean getStudentPage(StudentQueryParam param) {
        // 使用自动分页查询组件
        PageHelper.startPage(param.getPage(),param.getPageSize());
        List<Student> students = studentMapper.getStudentPage(param);
        Page page = (Page) students;
        return new PageBean(page.getTotal(),page.getResult());
    }
    /**
     * 根据Id查询
     * */
    @Override
    public Student getStudentById(Integer id) {
        Student student = studentMapper.getStudentById(id);
        return student;
    }
    /**
     * 新增学员
     * */
    @Override
    public void addStudent(Student student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.addStudent(student);
    }
    /**
     * 修改学员信息
     * */
    @Override
    public void updateStudent(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.updateStudent(student);
    }
    /**
     * 批量删除学员
     * */
    @Override
    public void deleteStudent(Integer[] ids) {
        studentMapper.deleteStudent(ids);
    }
    /**
     * 违纪处理
     * */
    @Override
    public void violation(Integer id, Integer score) {
        studentMapper.updateViolation(id,score);
    }
}
